/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.timesoft.zk.common;

import org.zkoss.zk.ui.Desktop;
import org.zkoss.zul.Include;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.util.Map;
/**
 *
 * @author niwatr
 */
public class NavigatorUtil {
    private static Log LOG = LogFactory.getLog(NavigatorUtil.class);
    private Include include;
    public static final String PAGE_INCLUDE = "pageInc";

    public NavigatorUtil(String includeAttributeKey,Desktop desktop)
    {
        this.include = (Include)desktop.getAttribute(includeAttributeKey);
        if(include != null)
        {
            this.include.clearDynamicProperties();
        }
        else
        {
            LOG.warn(" --------can't create NavigatorUtil null content display......");
        }
    }

    public NavigatorUtil(Include include)
    {
        this.include = include;
        this.include.setProgressing(true);
        this.include.clearDynamicProperties();
    }

    public void gotoPage(String uri,String keyDynamicProperty, Object ObjectDynamicProperty)
    {
        if (null != ObjectDynamicProperty)
        {
            this.include.setDynamicProperty(keyDynamicProperty,ObjectDynamicProperty);
        }
        gotoPage(uri);
    }

    public void gotoPage(String uri, Map<String,Object> mapObject)
    {
        if (null != mapObject)
        {
            for(String key : mapObject.keySet()){
                this.include.setDynamicProperty(key,mapObject.get(key));
            }
        }
        gotoPage(uri);
    }

    public void gotoPage(String uri,String keyDynamicProperty, Object ObjectDynamicProperty,String editionParam,Long securityManagement)
    {
        if (null != ObjectDynamicProperty)
        {
            this.include.setDynamicProperty(keyDynamicProperty,ObjectDynamicProperty);
        }
        if(null != editionParam){
            this.include.setDynamicProperty("editionParam",editionParam);
        }
        if(null != securityManagement){
            this.include.setDynamicProperty("securityManagement", securityManagement);
        }
        gotoPage(uri);
    }

    public void gotoPage(String uri,String editionParam,Long securityManagement)
    {
        if(null != editionParam){
            this.include.setDynamicProperty("editionParam",editionParam);
            this.include.setDynamicProperty("securityManagement",securityManagement);
        }
        this.include.setSrc(uri);
    }

    public void gotoPage(String uri,String editionParam)
    {
        if(null != editionParam){
            this.include.setDynamicProperty("editionParam",editionParam);
        }
        this.include.setSrc(uri);
    }

    public void gotoPage(String uri)
    {
        this.include.setSrc("");
        this.include.setSrc(uri);
    }
}
